// Локальные
#include "math/math.h"
#include "geometry/2d/lineparam.h"

namespace geometry
{
    namespace _2d
    {
        //========================================================================================================================
        //========================================================================================================================
        void LineParam::findIntersection(const LineParam &line1, const LineParam &line2, double *t1, double *t2, bool *is_parallel)
        {
            if(qAbs(line1.m_Vector.x()/line2.m_Vector.x() - line1.m_Vector.y()/line2.m_Vector.y()) < DBL_EPSILON)
                *is_parallel = true;
            else
            {
                *is_parallel = false;
                *t2 = ((line1.m_Point.y() - line2.m_Point.y())*line1.m_Vector.x() - (line1.m_Point.x() - line2.m_Point.x())*line1.m_Vector.y())/
                        (line1.m_Vector.x()*line2.m_Vector.y() - line2.m_Vector.x()*line1.m_Vector.y());
                *t1 = (line2.m_Point.x() - line1.m_Point.x() + line2.m_Vector.x()*(*t2))/line1.m_Vector.x();
            }
        }
    }
}
